package com.ruoyi.teaching.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.teaching.domain.ScheduleManagement;
import com.ruoyi.teaching.service.IScheduleManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 课表管理Controller
 * 
 * @author thl
 * @date 2024-01-05
 */
@RestController
@RequestMapping("/scheduleManagement")
public class ScheduleManagementController extends BaseController
{
    @Autowired
    private IScheduleManagementService scheduleManagementService;

    /**
     * 查询课表管理列表
     */
    @RequiresPermissions("teaching:scheduleManagement:list")
    @GetMapping("/list")
    public TableDataInfo list(ScheduleManagement scheduleManagement)
    {
        startPage();
        List<ScheduleManagement> list = scheduleManagementService.selectScheduleManagementList(scheduleManagement);
        return getDataTable(list);
    }

    /**
     * 导出课表管理列表
     */
    @RequiresPermissions("teaching:scheduleManagement:export")
    @Log(title = "课表管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScheduleManagement scheduleManagement)
    {
        List<ScheduleManagement> list = scheduleManagementService.selectScheduleManagementList(scheduleManagement);
        ExcelUtil<ScheduleManagement> util = new ExcelUtil<ScheduleManagement>(ScheduleManagement.class);
        util.exportExcel(response, list, "课表管理数据");
    }

    /**
     * 获取课表管理详细信息
     */
    @RequiresPermissions("teaching:scheduleManagement:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(scheduleManagementService.selectScheduleManagementById(id));
    }

    /**
     * 新增课表管理
     */
    @RequiresPermissions("teaching:scheduleManagement:add")
    @Log(title = "课表管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScheduleManagement scheduleManagement)
    {
        return toAjax(scheduleManagementService.insertScheduleManagement(scheduleManagement));
    }

    /**
     * 修改课表管理
     */
    @RequiresPermissions("teaching:scheduleManagement:edit")
    @Log(title = "课表管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScheduleManagement scheduleManagement)
    {
        return toAjax(scheduleManagementService.updateScheduleManagement(scheduleManagement));
    }

    /**
     * 删除课表管理
     */
    @RequiresPermissions("teaching:scheduleManagement:remove")
    @Log(title = "课表管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(scheduleManagementService.deleteScheduleManagementByIds(ids));
    }
}
